package com.example.fms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.fms.FreightManagementSystemApplication;
import com.example.fms.dto.req.AddMinOrderRuleReqDto;
import com.example.fms.dto.req.MinOrderRuleReqDto;
import com.example.fms.dto.resp.MinOrderRuleRespDto;
import com.example.fms.entity.MinOrderRule;
import com.example.fms.service.MinOrderRuleService;
import com.example.fms.vo.ResponseBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;
import java.sql.SQLOutput;

@RestController
@RequestMapping("/minOrderRule")
@Slf4j
public class MinOrderRuleController {

    @Resource
    private MinOrderRuleService minOrderRuleService;

    /**
     * 获取最小规则分页查询
     * @param req 查询条件
     * @return 查询结果
     */
    @PostMapping("/getMinOrderRuleList")
    public ResponseBean<Page<MinOrderRuleRespDto>> getMinOrderRuleList(@RequestBody MinOrderRuleReqDto req) {
        return ResponseBean.success(minOrderRuleService.getMinOrderRuleList(req));
    }

    /**
     * 新增最小规则
     * @param req 新增最小规则
     * @return 是否成功
     */
    @PostMapping("/addMinOrderRule")
    public ResponseBean<Boolean> addMinOrderRuleList(@RequestBody @Valid AddMinOrderRuleReqDto req) {
        return ResponseBean.success(minOrderRuleService.addMinOrderRule(req));
    }

    /**
     * 删除最小规则
     * @param id 需要删除的id
     * @return 是否成功
     */
    @DeleteMapping("/deleteMinOrderRule/{id}")
    public ResponseBean<Boolean> deleteMinOrderRule(@PathVariable("id")  Long id) {
        return ResponseBean.success(minOrderRuleService.deleteMinOrderRule(id));
    }

    /**
     * 修改最小规则
     * @param req 修改内容
     * @return 是否成功
     */
    @PutMapping("/upDateMinOrderRule")
    public ResponseBean<Boolean> upDateMinOrderRule(@RequestBody @Valid AddMinOrderRuleReqDto req) {
        return ResponseBean.success(minOrderRuleService.upDateMinOrderRule(req));
    }




}



















